<?xml version="1.0"?>

<!-- 
  Simple RSS Aggregation for IEEE Computing Now Editors Blogs
  by George K. Thiruvathukal

  This basic transform accepts its input in a feeds document (see feeds.dtd
  for the required structure).

  The result will be a single RSS feed. This stylesheet can be transformed
  using any XSLT processor but Saxon is recommended at this time. 

  This is very much a work in progress and more is to come.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" 
  xmlns:georss="http://www.georss.org/georss"
  xmlns:aml="http://markup-languages.googlecode.com/ns/aml"
  version="1.0">
  
  <!-- Note: My list of xmlns bindings is not complete here. -->
  <xsl:output method="xml" indent="yes" />
  
  <xsl:template match="/feeds" >
    <aml:aggregated>
      <xsl:apply-templates select="feed[@provider = 'blogger' and @enabled = 'yes']" mode="rss20"/>
      <xsl:apply-templates select="feed[@provider = 'wordpress' and @enabled = 'yes']" mode="rss20"/>
    </aml:aggregated>
  </xsl:template>
  
  <xsl:template match="feed" mode="rss20">
    <xsl:element name="aml:blog">
      <xsl:copy-of select="@uri"/>  
      <xsl:variable name="docuri" select="@uri"/>
      <xsl:for-each select="keyword">
        <xsl:apply-templates select="document($docuri)//channel" mode="rss20">
          <xsl:with-param name="keyword" select="@name"/>
        </xsl:apply-templates>
      </xsl:for-each>
    </xsl:element>
  </xsl:template>
  
  <xsl:template match="channel" mode="rss20">
    <xsl:param name="keyword"/>
    <xsl:for-each select="item">
      <xsl:sort order="descending" select="atom:updated/text()"/>
      <xsl:for-each select="category">
        <xsl:if test="$keyword = text()">
          <xsl:copy-of select="../link"/>
        </xsl:if>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
  
</xsl:stylesheet>
